package service.impl;

import java.util.ArrayList;
import java.util.List;

import pojo.User;

import service.UserManager;

public class UserManagerImplMock implements UserManager{
private static List<User> users=new ArrayList<>();
private static int index=0;

static{
	User u=new User("tom","123",24,false,++index);
	User u1=new User("tom1","123",24,true,++index);
	users.add(u);
	users.add(u1);
}
	@Override
	public int regist(User u) {
		u.setId(++index);
		users.add(u);
		return 1;
	}

	@Override
	public User login(String name, String password) {
		User rs=null;
		for(User u:users){
			if(name.equals(u.getName())&&password.equals(u.getPassword())){
				rs=u;
				System.out.println(rs.getId()+"..login."+rs.getName());
				break;
			}
		}
	
		return rs;
	}

	@Override
	public List<User> findAllUsers() {
		// TODO Auto-generated method stub
		return users;
	}

	@Override
	public int fireUser(int id) {
		// TODO Auto-generated method stub
		System.out.println("fire");
		int m=0;
		User uu=null;
		for(User u:users){
			if(id==u.getId()){
				uu=u;
				m=1;
				break;
				
			}
		}
		users.remove(uu);
		return 0;
	}

}
